package com.freesky.biz.icbc.controller;

import com.freesky.biz.icbc.domain.TMobileRecharge;
import com.freesky.biz.icbc.domain.TPartnership;
import com.freesky.biz.icbc.service.IMobileRechargeService;
import com.freesky.biz.icbc.service.IPartnershipService;
import com.freesky.common.annotation.Log;
import com.freesky.common.annotation.RepeatSubmit;
import com.freesky.common.core.controller.BaseController;
import com.freesky.common.core.domain.AjaxResult;
import com.freesky.common.core.page.TableDataInfo;
import com.freesky.common.enums.BusinessType;
import com.freesky.common.exception.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 结伴创业，共赢未来
 */
@RestController
@RequestMapping("/icbc/partnership")
public class PartnershipController extends BaseController {

    @Autowired
    private IPartnershipService partnershipService;

    /**
     * 结伴创业列表
     */
    @PreAuthorize("@ss.hasPermi('icbc:partnership:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPartnership partnership) {
        startPage();
        List<TPartnership> list = partnershipService.findList(partnership);
        return getDataTable(list);
    }

    @Log(title = "结伴创业", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('icbc:partnership:export')")
    @GetMapping("/export")
    public AjaxResult export(TPartnership partnership,
                             HttpServletResponse response) {
        return partnershipService.exportFile(partnership);
    }

    @PreAuthorize("@ss.hasPermi('icbc:partnership:import')")
    //@Log(title = "结伴创业", businessType = BusinessType.IMPORT)
    @RepeatSubmit
    @RequestMapping("/template")
    public void exportExcel() {
        partnershipService.exportExcel();
    }

    //导入结伴创业
    @PreAuthorize("@ss.hasPermi('icbc:partnership:import')")
    @Log(title = "结伴创业", businessType = BusinessType.IMPORT)
    @RepeatSubmit
    @RequestMapping("/import")
    public AjaxResult importExcel(MultipartFile file) throws Exception {
        if (file.isEmpty()) {
            throw new CustomException("导入文件不能为空！");
        }
        return partnershipService.importExcel(file,"1");
    }

    @PreAuthorize("@ss.hasPermi('icbc:partnership:import')")
    @Log(title = "企业达标有礼", businessType = BusinessType.IMPORT)
    @RepeatSubmit
    @RequestMapping("/importReach")
    public AjaxResult importReach(MultipartFile file) throws Exception {
        if (file.isEmpty()) {
            throw new CustomException("导入文件不能为空！");
        }
        return partnershipService.importExcel(file,"2");
    }
}
